/**
 * TCSS343, Dr. Chinn, HW6B, 12/3/2011
 * Dijkstra's Algorithm
 * @author James Gunter
 * @author Justin Kudlo
 * @author Ryan Erickson
 */

public class DijkstraNode implements Comparable<DijkstraNode>{
	/**
	 * Whether or not the node is in the known set.
	 */
	private boolean 		known;
	/**
	 * The current label applied to the node. (Will be the minimum path cost from the source).
	 */
	private Double     		label;
	/**
	 * The Vertex object in the graph that this node points to.
	 */
	private Vertex 			vertex_ptr;
	/**
	 * The node that you took to get to this node when travelling the shortest path.
	 */
	private DijkstraNode 	previous_node_ptr;
	/**
	 * The index in the heap's array backing store so that we can easily call percolateUp() on this node.
	 */
	private int				heap_location;
	
	/**
	 * Constructor for creating a DijkstraNode with an associated Vertex 
	 * ptr set to null
	 * Sets the node to infinity (MAX_VALUE)
	 * Sets the known set variable to false
	 * Sets the Heap location to zero so that it can be perculated down.  
	 */
	public DijkstraNode() {
		setKnown(false);
		setLabel(Double.MAX_VALUE);
		setVertexPtr(null);
		setPreviousNodePtr(null);
		setHeapLocation(0);
	}
	
	/**
	 * Constructor for creating a DijkstraNode with an input of the associated 
	 * Vertex ptr
	 * Sets the node to infinity (MAX_VALUE)
	 * Sets the known set variable to false
	 * Sets the Heap location to zero so that it can be perculated down.
	 * @param v, the vertex used to arrive at Node.  
	 */
	public DijkstraNode(Vertex v) {
		setKnown(false);
		setLabel(Double.MAX_VALUE);
		setVertexPtr(v);
		setPreviousNodePtr(null);
		setHeapLocation(0);
	}
	
	/**
	 * Sets the node to true or false if node/vertex is part of the known set
	 * @param k, a boolean value representing the node being part of the known 
	 * set
	 */
	public void setKnown(boolean k) {
		known = k;
	}
	
	/**
	 * Returns the status of the node as part of the known set
	 * @return the status of the node as part of the known set
	 */
	public boolean getKnown() {
		return known;
	}
	
	/**
	 * Set/relabel the label of the node based upon the new found distance
	 * @param l, the new label distance to be associated with this node
	 */
	public void setLabel (Double l) {
		label = l;
	}
	
	/**
	 * Return the label/distance of the node/vertex being made up of the 
	 * shortest path weights added together 
	 * @return the label/distance of the node/vertex
	 */
	public Double getLabel() {
		return label;
	}
	
	/**
	 * The vertex associated with this node (doubly linked)
	 * @param v, the vertex associated with this node (doubly linked)
	 */
	public void setVertexPtr(Vertex v) {
		vertex_ptr = v;
	}
	
	/**
	 * Return the vertex associated with this node (doubly linked)
	 * @return the vertex associated with this node (doubly linked)
	 */
	public Vertex getVertexPtr() {
		return vertex_ptr;
	}

	/**
	 * Sets a pointer to the previous Dijkstra node in the heap
	 * @param p, a pointer to the previous Dijkstra node in the heap
	 */
	public void setPreviousNodePtr(DijkstraNode p) {
		previous_node_ptr = p;
	}
	
	/**
	 * Returns a pointer to the previous Dijkstra node in the heap
	 * @return a pointer to the previous Dijkstra node in the heap
	 */
	public DijkstraNode getPreviousNodePtr() {
		return previous_node_ptr;
	}
	
	/**
	 * Sets the nodes location relative to the heap 
	 * @param h, int value based on heap location
	 */
	public void setHeapLocation (int h) {
		heap_location = h;
	}
	
	/**
	 * Returns the nodes location relative to the heap  
	 * @return int value based on heap location
	 */
	public int getHeapLocation () {
		return heap_location;
	}

	/**
	 * Used by BinaryHeap to compare nodes against each other based upon label
	 * value.
	 * @return an int value, positive=larger, negative=smaller, or zero=same
	 */
	@Override
	public int compareTo(DijkstraNode other) {
		return getLabel().compareTo(other.getLabel());
	}

	
}